import { createApp } from "vue";

import App from "./App.vue";
import Card from "./components/Card/index.vue";
import Chart from "./components/Chart/index.vue";

// 在 main.ts 引入全局或公共的内容
import "normalize.css"; // pnpm add normalize.css
import "./styles/global.scss"; // pnpm add sass -D
import "./styles/variables.css";

let app;
const render = (props) => {
  app = createApp(App);
  // 全局注册组件
  app.component("Card", Card);
  app.component("Chart", Chart);
  app.mount(props.container ? props.container.querySelector("#app") : "#app");
};

import {
  renderWithQiankun,
  qiankunWindow,
} from "vite-plugin-qiankun/dist/helper";

renderWithQiankun({
  mount(props) {
    render(props);
  },
  bootstrap() {},
  unmount(props: any) {
    app.unmount();
    app = null;
  },
});

if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render({});
}
